package com.evzgaga.evzrecon.io;

import java.io.IOException;
import java.io.InputStream;
import com.evzgaga.evzrecon.util.LittleEndianConverter;

/**
 * A wrapper around an {@link InputStream} which provides method
 * for values in little endian ordering.
 * 
 * @author Bastien
 */
public class LittleEndianDataInputStream {

    private InputStream wrappedInputStream;
    
    public static LittleEndianDataInputStream wrap(InputStream stream) {
        return new LittleEndianDataInputStream(stream);
    }

    private LittleEndianDataInputStream(InputStream stream) {
        wrappedInputStream = stream;
    }
    
    public int readInt() throws IOException {
        byte data[] = new byte[4];
        
        wrappedInputStream.read(data);
        
        return LittleEndianConverter.fromLittleEndian(data);
    }
   
    //TODO: proxy around the input stream?
    public void read(byte[] b) throws IOException {
        wrappedInputStream.read(b);
    }
    
    public int available() throws IOException {
        return wrappedInputStream.available();
    }
}
